<?php


abstract class BaseTurno extends BaseObject  implements Persistent {


	
	protected static $peer;


	
	protected $id;


	
	protected $nom_turno;

	
	protected $collBloques;

	
	protected $lastBloqueCriteria = null;

	
	protected $collCitas;

	
	protected $lastCitaCriteria = null;

	
	protected $collHorarios;

	
	protected $lastHorarioCriteria = null;

	
	protected $collSesionAsesorias;

	
	protected $lastSesionAsesoriaCriteria = null;

	
	protected $alreadyInSave = false;

	
	protected $alreadyInValidation = false;

	
	public function getId()
	{

		return $this->id;
	}

	
	public function getNomTurno()
	{

		return $this->nom_turno;
	}

	
	public function setId($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->id !== $v) {
			$this->id = $v;
			$this->modifiedColumns[] = TurnoPeer::ID;
		}

	} 
	
	public function setNomTurno($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->nom_turno !== $v) {
			$this->nom_turno = $v;
			$this->modifiedColumns[] = TurnoPeer::NOM_TURNO;
		}

	} 
	
	public function hydrate(ResultSet $rs, $startcol = 1)
	{
		try {

			$this->id = $rs->getInt($startcol + 0);

			$this->nom_turno = $rs->getString($startcol + 1);

			$this->resetModified();

			$this->setNew(false);

						return $startcol + 2; 
		} catch (Exception $e) {
			throw new PropelException("Error populating Turno object", $e);
		}
	}

	
	public function delete($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("This object has already been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(TurnoPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			TurnoPeer::doDelete($this, $con);
			$this->setDeleted(true);
			$con->commit();
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	public function save($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("You cannot save an object that has been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(TurnoPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			$affectedRows = $this->doSave($con);
			$con->commit();
			return $affectedRows;
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	protected function doSave($con)
	{
		$affectedRows = 0; 		if (!$this->alreadyInSave) {
			$this->alreadyInSave = true;


						if ($this->isModified()) {
				if ($this->isNew()) {
					$pk = TurnoPeer::doInsert($this, $con);
					$affectedRows += 1; 										 										 
					$this->setId($pk);  
					$this->setNew(false);
				} else {
					$affectedRows += TurnoPeer::doUpdate($this, $con);
				}
				$this->resetModified(); 			}

			if ($this->collBloques !== null) {
				foreach($this->collBloques as $referrerFK) {
					if (!$referrerFK->isDeleted()) {
						$affectedRows += $referrerFK->save($con);
					}
				}
			}

			if ($this->collCitas !== null) {
				foreach($this->collCitas as $referrerFK) {
					if (!$referrerFK->isDeleted()) {
						$affectedRows += $referrerFK->save($con);
					}
				}
			}

			if ($this->collHorarios !== null) {
				foreach($this->collHorarios as $referrerFK) {
					if (!$referrerFK->isDeleted()) {
						$affectedRows += $referrerFK->save($con);
					}
				}
			}

			if ($this->collSesionAsesorias !== null) {
				foreach($this->collSesionAsesorias as $referrerFK) {
					if (!$referrerFK->isDeleted()) {
						$affectedRows += $referrerFK->save($con);
					}
				}
			}

			$this->alreadyInSave = false;
		}
		return $affectedRows;
	} 
	
	protected $validationFailures = array();

	
	public function getValidationFailures()
	{
		return $this->validationFailures;
	}

	
	public function validate($columns = null)
	{
		$res = $this->doValidate($columns);
		if ($res === true) {
			$this->validationFailures = array();
			return true;
		} else {
			$this->validationFailures = $res;
			return false;
		}
	}

	
	protected function doValidate($columns = null)
	{
		if (!$this->alreadyInValidation) {
			$this->alreadyInValidation = true;
			$retval = null;

			$failureMap = array();


			if (($retval = TurnoPeer::doValidate($this, $columns)) !== true) {
				$failureMap = array_merge($failureMap, $retval);
			}


				if ($this->collBloques !== null) {
					foreach($this->collBloques as $referrerFK) {
						if (!$referrerFK->validate($columns)) {
							$failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
						}
					}
				}

				if ($this->collCitas !== null) {
					foreach($this->collCitas as $referrerFK) {
						if (!$referrerFK->validate($columns)) {
							$failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
						}
					}
				}

				if ($this->collHorarios !== null) {
					foreach($this->collHorarios as $referrerFK) {
						if (!$referrerFK->validate($columns)) {
							$failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
						}
					}
				}

				if ($this->collSesionAsesorias !== null) {
					foreach($this->collSesionAsesorias as $referrerFK) {
						if (!$referrerFK->validate($columns)) {
							$failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
						}
					}
				}


			$this->alreadyInValidation = false;
		}

		return (!empty($failureMap) ? $failureMap : true);
	}

	
	public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = TurnoPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->getByPosition($pos);
	}

	
	public function getByPosition($pos)
	{
		switch($pos) {
			case 0:
				return $this->getId();
				break;
			case 1:
				return $this->getNomTurno();
				break;
			default:
				return null;
				break;
		} 	}

	
	public function toArray($keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = TurnoPeer::getFieldNames($keyType);
		$result = array(
			$keys[0] => $this->getId(),
			$keys[1] => $this->getNomTurno(),
		);
		return $result;
	}

	
	public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = TurnoPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->setByPosition($pos, $value);
	}

	
	public function setByPosition($pos, $value)
	{
		switch($pos) {
			case 0:
				$this->setId($value);
				break;
			case 1:
				$this->setNomTurno($value);
				break;
		} 	}

	
	public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = TurnoPeer::getFieldNames($keyType);

		if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
		if (array_key_exists($keys[1], $arr)) $this->setNomTurno($arr[$keys[1]]);
	}

	
	public function buildCriteria()
	{
		$criteria = new Criteria(TurnoPeer::DATABASE_NAME);

		if ($this->isColumnModified(TurnoPeer::ID)) $criteria->add(TurnoPeer::ID, $this->id);
		if ($this->isColumnModified(TurnoPeer::NOM_TURNO)) $criteria->add(TurnoPeer::NOM_TURNO, $this->nom_turno);

		return $criteria;
	}

	
	public function buildPkeyCriteria()
	{
		$criteria = new Criteria(TurnoPeer::DATABASE_NAME);

		$criteria->add(TurnoPeer::ID, $this->id);

		return $criteria;
	}

	
	public function getPrimaryKey()
	{
		return $this->getId();
	}

	
	public function setPrimaryKey($key)
	{
		$this->setId($key);
	}

	
	public function copyInto($copyObj, $deepCopy = false)
	{

		$copyObj->setNomTurno($this->nom_turno);


		if ($deepCopy) {
									$copyObj->setNew(false);

			foreach($this->getBloques() as $relObj) {
				$copyObj->addBloque($relObj->copy($deepCopy));
			}

			foreach($this->getCitas() as $relObj) {
				$copyObj->addCita($relObj->copy($deepCopy));
			}

			foreach($this->getHorarios() as $relObj) {
				$copyObj->addHorario($relObj->copy($deepCopy));
			}

			foreach($this->getSesionAsesorias() as $relObj) {
				$copyObj->addSesionAsesoria($relObj->copy($deepCopy));
			}

		} 

		$copyObj->setNew(true);

		$copyObj->setId(NULL); 
	}

	
	public function copy($deepCopy = false)
	{
				$clazz = get_class($this);
		$copyObj = new $clazz();
		$this->copyInto($copyObj, $deepCopy);
		return $copyObj;
	}

	
	public function getPeer()
	{
		if (self::$peer === null) {
			self::$peer = new TurnoPeer();
		}
		return self::$peer;
	}

	
	public function initBloques()
	{
		if ($this->collBloques === null) {
			$this->collBloques = array();
		}
	}

	
	public function getBloques($criteria = null, $con = null)
	{
				include_once 'lib/model/om/BaseBloquePeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collBloques === null) {
			if ($this->isNew()) {
			   $this->collBloques = array();
			} else {

				$criteria->add(BloquePeer::TURNO_ID, $this->getId());

				BloquePeer::addSelectColumns($criteria);
				$this->collBloques = BloquePeer::doSelect($criteria, $con);
			}
		} else {
						if (!$this->isNew()) {
												

				$criteria->add(BloquePeer::TURNO_ID, $this->getId());

				BloquePeer::addSelectColumns($criteria);
				if (!isset($this->lastBloqueCriteria) || !$this->lastBloqueCriteria->equals($criteria)) {
					$this->collBloques = BloquePeer::doSelect($criteria, $con);
				}
			}
		}
		$this->lastBloqueCriteria = $criteria;
		return $this->collBloques;
	}

	
	public function countBloques($criteria = null, $distinct = false, $con = null)
	{
				include_once 'lib/model/om/BaseBloquePeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		$criteria->add(BloquePeer::TURNO_ID, $this->getId());

		return BloquePeer::doCount($criteria, $distinct, $con);
	}

	
	public function addBloque(Bloque $l)
	{
		$this->collBloques[] = $l;
		$l->setTurno($this);
	}

	
	public function initCitas()
	{
		if ($this->collCitas === null) {
			$this->collCitas = array();
		}
	}

	
	public function getCitas($criteria = null, $con = null)
	{
				include_once 'lib/model/om/BaseCitaPeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collCitas === null) {
			if ($this->isNew()) {
			   $this->collCitas = array();
			} else {

				$criteria->add(CitaPeer::TURNO_ID, $this->getId());

				CitaPeer::addSelectColumns($criteria);
				$this->collCitas = CitaPeer::doSelect($criteria, $con);
			}
		} else {
						if (!$this->isNew()) {
												

				$criteria->add(CitaPeer::TURNO_ID, $this->getId());

				CitaPeer::addSelectColumns($criteria);
				if (!isset($this->lastCitaCriteria) || !$this->lastCitaCriteria->equals($criteria)) {
					$this->collCitas = CitaPeer::doSelect($criteria, $con);
				}
			}
		}
		$this->lastCitaCriteria = $criteria;
		return $this->collCitas;
	}

	
	public function countCitas($criteria = null, $distinct = false, $con = null)
	{
				include_once 'lib/model/om/BaseCitaPeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		$criteria->add(CitaPeer::TURNO_ID, $this->getId());

		return CitaPeer::doCount($criteria, $distinct, $con);
	}

	
	public function addCita(Cita $l)
	{
		$this->collCitas[] = $l;
		$l->setTurno($this);
	}


	
	public function getCitasJoinAteneausuarioRelatedByEspecialistaId($criteria = null, $con = null)
	{
				include_once 'lib/model/om/BaseCitaPeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collCitas === null) {
			if ($this->isNew()) {
				$this->collCitas = array();
			} else {

				$criteria->add(CitaPeer::TURNO_ID, $this->getId());

				$this->collCitas = CitaPeer::doSelectJoinAteneausuarioRelatedByEspecialistaId($criteria, $con);
			}
		} else {
									
			$criteria->add(CitaPeer::TURNO_ID, $this->getId());

			if (!isset($this->lastCitaCriteria) || !$this->lastCitaCriteria->equals($criteria)) {
				$this->collCitas = CitaPeer::doSelectJoinAteneausuarioRelatedByEspecialistaId($criteria, $con);
			}
		}
		$this->lastCitaCriteria = $criteria;

		return $this->collCitas;
	}


	
	public function getCitasJoinAteneausuarioRelatedBySolicitanteId($criteria = null, $con = null)
	{
				include_once 'lib/model/om/BaseCitaPeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collCitas === null) {
			if ($this->isNew()) {
				$this->collCitas = array();
			} else {

				$criteria->add(CitaPeer::TURNO_ID, $this->getId());

				$this->collCitas = CitaPeer::doSelectJoinAteneausuarioRelatedBySolicitanteId($criteria, $con);
			}
		} else {
									
			$criteria->add(CitaPeer::TURNO_ID, $this->getId());

			if (!isset($this->lastCitaCriteria) || !$this->lastCitaCriteria->equals($criteria)) {
				$this->collCitas = CitaPeer::doSelectJoinAteneausuarioRelatedBySolicitanteId($criteria, $con);
			}
		}
		$this->lastCitaCriteria = $criteria;

		return $this->collCitas;
	}


	
	public function getCitasJoinBloque($criteria = null, $con = null)
	{
				include_once 'lib/model/om/BaseCitaPeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collCitas === null) {
			if ($this->isNew()) {
				$this->collCitas = array();
			} else {

				$criteria->add(CitaPeer::TURNO_ID, $this->getId());

				$this->collCitas = CitaPeer::doSelectJoinBloque($criteria, $con);
			}
		} else {
									
			$criteria->add(CitaPeer::TURNO_ID, $this->getId());

			if (!isset($this->lastCitaCriteria) || !$this->lastCitaCriteria->equals($criteria)) {
				$this->collCitas = CitaPeer::doSelectJoinBloque($criteria, $con);
			}
		}
		$this->lastCitaCriteria = $criteria;

		return $this->collCitas;
	}

	
	public function initHorarios()
	{
		if ($this->collHorarios === null) {
			$this->collHorarios = array();
		}
	}

	
	public function getHorarios($criteria = null, $con = null)
	{
				include_once 'lib/model/om/BaseHorarioPeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collHorarios === null) {
			if ($this->isNew()) {
			   $this->collHorarios = array();
			} else {

				$criteria->add(HorarioPeer::TURNO_ID, $this->getId());

				HorarioPeer::addSelectColumns($criteria);
				$this->collHorarios = HorarioPeer::doSelect($criteria, $con);
			}
		} else {
						if (!$this->isNew()) {
												

				$criteria->add(HorarioPeer::TURNO_ID, $this->getId());

				HorarioPeer::addSelectColumns($criteria);
				if (!isset($this->lastHorarioCriteria) || !$this->lastHorarioCriteria->equals($criteria)) {
					$this->collHorarios = HorarioPeer::doSelect($criteria, $con);
				}
			}
		}
		$this->lastHorarioCriteria = $criteria;
		return $this->collHorarios;
	}

	
	public function countHorarios($criteria = null, $distinct = false, $con = null)
	{
				include_once 'lib/model/om/BaseHorarioPeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		$criteria->add(HorarioPeer::TURNO_ID, $this->getId());

		return HorarioPeer::doCount($criteria, $distinct, $con);
	}

	
	public function addHorario(Horario $l)
	{
		$this->collHorarios[] = $l;
		$l->setTurno($this);
	}


	
	public function getHorariosJoinEvento($criteria = null, $con = null)
	{
				include_once 'lib/model/om/BaseHorarioPeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collHorarios === null) {
			if ($this->isNew()) {
				$this->collHorarios = array();
			} else {

				$criteria->add(HorarioPeer::TURNO_ID, $this->getId());

				$this->collHorarios = HorarioPeer::doSelectJoinEvento($criteria, $con);
			}
		} else {
									
			$criteria->add(HorarioPeer::TURNO_ID, $this->getId());

			if (!isset($this->lastHorarioCriteria) || !$this->lastHorarioCriteria->equals($criteria)) {
				$this->collHorarios = HorarioPeer::doSelectJoinEvento($criteria, $con);
			}
		}
		$this->lastHorarioCriteria = $criteria;

		return $this->collHorarios;
	}


	
	public function getHorariosJoinAteneausuario($criteria = null, $con = null)
	{
				include_once 'lib/model/om/BaseHorarioPeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collHorarios === null) {
			if ($this->isNew()) {
				$this->collHorarios = array();
			} else {

				$criteria->add(HorarioPeer::TURNO_ID, $this->getId());

				$this->collHorarios = HorarioPeer::doSelectJoinAteneausuario($criteria, $con);
			}
		} else {
									
			$criteria->add(HorarioPeer::TURNO_ID, $this->getId());

			if (!isset($this->lastHorarioCriteria) || !$this->lastHorarioCriteria->equals($criteria)) {
				$this->collHorarios = HorarioPeer::doSelectJoinAteneausuario($criteria, $con);
			}
		}
		$this->lastHorarioCriteria = $criteria;

		return $this->collHorarios;
	}

	
	public function initSesionAsesorias()
	{
		if ($this->collSesionAsesorias === null) {
			$this->collSesionAsesorias = array();
		}
	}

	
	public function getSesionAsesorias($criteria = null, $con = null)
	{
				include_once 'lib/model/om/BaseSesionAsesoriaPeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collSesionAsesorias === null) {
			if ($this->isNew()) {
			   $this->collSesionAsesorias = array();
			} else {

				$criteria->add(SesionAsesoriaPeer::TURNO_ID, $this->getId());

				SesionAsesoriaPeer::addSelectColumns($criteria);
				$this->collSesionAsesorias = SesionAsesoriaPeer::doSelect($criteria, $con);
			}
		} else {
						if (!$this->isNew()) {
												

				$criteria->add(SesionAsesoriaPeer::TURNO_ID, $this->getId());

				SesionAsesoriaPeer::addSelectColumns($criteria);
				if (!isset($this->lastSesionAsesoriaCriteria) || !$this->lastSesionAsesoriaCriteria->equals($criteria)) {
					$this->collSesionAsesorias = SesionAsesoriaPeer::doSelect($criteria, $con);
				}
			}
		}
		$this->lastSesionAsesoriaCriteria = $criteria;
		return $this->collSesionAsesorias;
	}

	
	public function countSesionAsesorias($criteria = null, $distinct = false, $con = null)
	{
				include_once 'lib/model/om/BaseSesionAsesoriaPeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		$criteria->add(SesionAsesoriaPeer::TURNO_ID, $this->getId());

		return SesionAsesoriaPeer::doCount($criteria, $distinct, $con);
	}

	
	public function addSesionAsesoria(SesionAsesoria $l)
	{
		$this->collSesionAsesorias[] = $l;
		$l->setTurno($this);
	}


	
	public function getSesionAsesoriasJoinAteneausuario($criteria = null, $con = null)
	{
				include_once 'lib/model/om/BaseSesionAsesoriaPeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collSesionAsesorias === null) {
			if ($this->isNew()) {
				$this->collSesionAsesorias = array();
			} else {

				$criteria->add(SesionAsesoriaPeer::TURNO_ID, $this->getId());

				$this->collSesionAsesorias = SesionAsesoriaPeer::doSelectJoinAteneausuario($criteria, $con);
			}
		} else {
									
			$criteria->add(SesionAsesoriaPeer::TURNO_ID, $this->getId());

			if (!isset($this->lastSesionAsesoriaCriteria) || !$this->lastSesionAsesoriaCriteria->equals($criteria)) {
				$this->collSesionAsesorias = SesionAsesoriaPeer::doSelectJoinAteneausuario($criteria, $con);
			}
		}
		$this->lastSesionAsesoriaCriteria = $criteria;

		return $this->collSesionAsesorias;
	}


	
	public function getSesionAsesoriasJoinDatoEstudiante($criteria = null, $con = null)
	{
				include_once 'lib/model/om/BaseSesionAsesoriaPeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collSesionAsesorias === null) {
			if ($this->isNew()) {
				$this->collSesionAsesorias = array();
			} else {

				$criteria->add(SesionAsesoriaPeer::TURNO_ID, $this->getId());

				$this->collSesionAsesorias = SesionAsesoriaPeer::doSelectJoinDatoEstudiante($criteria, $con);
			}
		} else {
									
			$criteria->add(SesionAsesoriaPeer::TURNO_ID, $this->getId());

			if (!isset($this->lastSesionAsesoriaCriteria) || !$this->lastSesionAsesoriaCriteria->equals($criteria)) {
				$this->collSesionAsesorias = SesionAsesoriaPeer::doSelectJoinDatoEstudiante($criteria, $con);
			}
		}
		$this->lastSesionAsesoriaCriteria = $criteria;

		return $this->collSesionAsesorias;
	}

} 